package no.progark.golf.controller;

import no.progark.golf.R;
import no.progark.golf.activities.GameActivity;
import no.progark.golf.activities.ScoreBoardActivity;
import no.progark.golf.views.TestView;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

public class MenuBarController {
	
	private static ImageButton wallButton;
	private static ImageButton settingsButton;
	private static ImageButton eyeButton;
	private static ImageButton scoreBoardButton;
	
	private static boolean wallButtonEnabled = false;
	private static boolean eyeButtonEnabled = true;
	
	private static Context context;
	
	public static void setContext(Context c){
		MenuBarController.context = c;
	}
	
	//WALLBUTTON
	
	public static void setWallButton(ImageButton b){
		MenuBarController.wallButton = b;
		wallButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(!wallButtonEnabled){
					wallButton.setImageResource(R.drawable.lineselected);
					eyeButton.setImageResource(R.drawable.shoot);
					TestView.reset();
					wallButtonEnabled = true;
					eyeButtonEnabled = false;
				}
			}
		});
	}
	
	public static ImageButton getWallButton(){
		return MenuBarController.wallButton;
	}
	
	public static boolean isWallButtonEnabled(){
		return wallButtonEnabled;
	}
	
	
	//SETTINGSBUTTON
	
	public static void setSettingsButton(ImageButton b){
		MenuBarController.settingsButton = b;
//		settingsButton.setOnClickListener(new OnClickListener() {
//			public void onClick(View v) {
//				
//			}
//		});
		
		settingsButton.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if(event.getAction() == MotionEvent.ACTION_DOWN){
					settingsButton.setImageResource(R.drawable.settingspressed);
				}
				if(event.getAction()  == MotionEvent.ACTION_UP){
					TestView.setUpandDown();
					TestView.removeLastWall();
					settingsButton.setImageResource(R.drawable.settings);
				}
				return true;
			}
		});
		
	}
	
	public static ImageButton setSettingsButton(){
		return MenuBarController.settingsButton;
	}
	
	public static ImageButton getSettingsButton(){
		return settingsButton;
	}
	
	//EYEBUTTON
	
	public static void setEyeButton(ImageButton b){
		MenuBarController.eyeButton= b;
		eyeButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if(!eyeButtonEnabled){
					wallButton.setImageResource(R.drawable.line);
					eyeButton.setImageResource(R.drawable.shootselected);
					TestView.reset();
					eyeButtonEnabled = true;
					wallButtonEnabled = false;
				}
			}
		});
	}	
	
	public static ImageButton setEyeButton(){
		return MenuBarController.eyeButton;
	}
	
	public static boolean isEyeButtonEnabled(){
		return eyeButtonEnabled;
	}
	
	//SCOREBOARDBUTTON
	
	public static void setScoreBoardButton(ImageButton b){
		MenuBarController.scoreBoardButton= b;
		scoreBoardButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
//				final Dialog dia = new Dialog(context);
//				dia.setContentView(R.layout.scoreboard);
//				dia.setCancelable(true);
//				dia.show();
				Intent i = new Intent(context, ScoreBoardActivity.class);
				context.startActivity(i);
			}
		});
	}
	
	public static ImageButton getScoreBoardButton(){
		return MenuBarController.scoreBoardButton;
	}
	

}
